package com.djl.homework;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * @Author djl
 * @Time 2024/9/29 20:20
 */
public class File implements Runnable{
    private String filePath;
    private List<Object> usersList;
    private CountDownLatch latch;
    public File(String filePath, List<Object> usersList, CountDownLatch latch) {
        this.filePath = filePath;
        this.usersList = usersList;
        this.latch = latch;
    }

    @Override
    public void run() {
        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;
            StringBuilder jsonBuilder = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                jsonBuilder.append(line);
            }
            usersList.add(jsonBuilder.toString());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            latch.countDown();
        }
    }
}
